<template lang="pug">
  <el-container class="layout-base" v-if="this.client==='android'">
    <el-aside style="width:0px" class="layout-aside">
      el-menu.layout-menu( @open="handleOpen" @close="handleClose" ,background-color="#545c64", text-color="#fff", active-text-color="#ffd04b", :default-active="activeNav", :router="true", :unique-opened="true")
        div(v-for='(nav, idx) in navs', :key='idx')
          el-submenu(v-if='nav.children && nav.children.length > 0', :index='nav.routeName')
            template(slot='title')
              .nav-text-inline
                img(:src="nav.icon", height="16")
                | {{nav.title}}
            el-menu-item(v-for='(child, i) in nav.children', :key='i', :index='child.routeName', :route='{name: child.routeName}') {{child.title}}
          el-menu-item(v-else, :index='nav.routeName', :route='{name: nav.routeName}')
            .nav-text-inline
              img(:src="nav.icon", height="16")
              | {{nav.title}}
    </el-aside> 
    el-container
      el-main
        router-view
  </el-container>
  <el-container class="layout-base" v-else >
    <el-aside :width="isCollapse ? '40px' : '200px'" class="layout-aside">
      //- el-header.menu-header(height='60px') 
      //-   <el-col :span="6" style="padding-top:8px">
      //-     //- img.logo(:src='imgs.Logo' )
      //-   </el-col>
      //-   <el-col :span="18" style="padding-left:10px">
      //-     font 管理测试系统
      //-   </el-col>
      <el-button class="toggle-button" type="text" @click="toggleCollapse">管理测试系统</el-button>
      el-menu.layout-menu( :headers="{Authorization:currentUser.token}" @open="handleOpen" @close="handleClose" ,background-color="#545c64", text-color="#fff", active-text-color="#ffd04b", :default-active="activeNav", :router="true", :unique-opened="true" :collapse="isCollapse" :collapse-transition="false")
        div(v-for='(nav, idx) in navs', :key='idx')
          el-submenu(v-if='nav.children && nav.children.length > 0', :index='nav.routeName')
            template(slot='title')
              .nav-text-inline
                img(:src="nav.icon", height="16")
                | {{nav.title}}
            el-menu-item(v-for='(child, i) in nav.children', :key='i', :index='child.routeName', :route='{name: child.routeName}') {{child.title}}
          el-menu-item(v-else, :index='nav.routeName', :route='{name: nav.routeName}')
            .nav-text-inline
              img(:src="nav.icon", height="16")
              | {{nav.title}}
    </el-aside>
    el-container
      el-header.main-header
        span
        span
        span
        span
        span
        span
        span
        span
        span
        span
        span
        span
        span
        span
        span
        span
        span
        span
        span
        span
        <router-link :to='{name: "index"}'>
          <el-badge :value="value1" class="item" style="float:right; display: none;" @click.native="chang()">
          <i class="el-icon-bell" style="font-size:25px;color:#3399CC"></i>
          </el-badge>
        </router-link>   
          el-dropdown(@command='handleDropCommand')
            span
              font {{this.currentUser ? this.currentUser.userName : ''}}
              i.el-icon-arrow-down.el-icon--right
            el-dropdown-menu(slot='dropdown')
              el-dropdown-item(command='handleLogout')
                font 安全退出             
      el-main
        <router-view/>
        <el-dialog title="新消息"  :visible.sync="addEventdialogVisible">
          <el-form label-width="150px" :model="information">
            <el-form-item label="消息内容:" >{{messageText}}</el-form-item>
            <el-form-item label="发送时间:" >{{messageDate}}</el-form-item>
          </el-form>
          <span slot="footer" class="dialog-footer" >
              <el-button type="primary"  @click="handleSubmit()">确 定</el-button>   
          </span>
        </el-dialog>
  </el-container>
</template>

<script>
import {updateMessage,notReadMessage} from '../services/message'
import CurrentUser from '../store/CurrentUser'
import Logo from '../assets/resources/logo.jpg'
// import NAV_ITEMS from '../navis'
import Vue from 'vue'
import VueCookies from 'vue-cookies'
import {GetNaviByUserRole} from '../services/navisBar'

import IconDashBoard from '../assets/icons/dashboard.svg'
import IconSystem from '../assets/icons/system.svg'
import IconConfig from '../assets/icons/config.svg'
import IconAnalysis from '../assets/icons/analysis.svg'
import IconPatrol from '../assets/icons/patrol.svg'
import IconList from '../assets/icons/list.svg'
//addicon
import IconCQPerson from '../assets/icons/people-line.svg'
import IconSupervision from '../assets/icons/detail-fill.svg'
import IconRegulations from '../assets/icons/pc-date.svg'
import IconAudit from '../assets/icons/audit.svg'
// import IconEventAndAccident from '../assets/icons/EventAndAccident.svg'
import IconStudyCase from '../assets/icons/StudyCase.svg'
import IconPersonalCenter from '../assets/icons/personalCenter.svg'
import {GetCurrentUser} from '../store/CurrentUser'  //新增
Vue.use(VueCookies)

export default {
  data() {
    return {
      client:VueCookies.get("client"),
      // isCollapse: true,
      navs: [],
      imgs: {
        Logo
      },
      websock: null,//测试websocket
      information:{},
      addEventdialogVisible:false,
      messageText:'',
      messageDate:'',
      messageId:'',
      value1:'',
      value2:'',
      timer:'',
      isCollapse: false
    }
  },
  created() {
    //页面刚进入时开启长连接
    if(this.client !='android')
    {
      this.initWebSocket();
    }
    },
    destroyed: function() {
    //页面销毁时关闭长连接
    this.websocketclose();
    },
  beforeMount () {
    this.checkUser()
  },
  watch:{
    $route(to){
      let routeName = to.name
      if (routeName != 'ExecuteTask' && routeName != 'SceneCheck' && routeName != 'ResidentStationCheck'){
        sessionStorage.removeItem('executeTaskData')
        sessionStorage.removeItem('executeTableData')
        sessionStorage.removeItem('executeTaskData')
      }
    }
  },
  mounted () {
    //定时刷新消息数量
    if(this.timer){
      clearInterval(this.timer)
    }else{
      this.timer=setInterval(()=>{
        this.getMessageCount()
      },3600000)
    }
    // if(this.timer){
    //   clearTimeout(this.timer)
    // }else{
    //   this.timer=setTimeout(()=>{
    //     this.getMessageCount()
    //   },2000)
    // }
    // this.getApiData()
    this.getMessageCount()
    this.GetModule()
    window.onload = function(){
      if(!window.sessionStorage["tempFlag"]){
        VueCookies.remove("store-current-user")
        location.reload();   //不能省，强制跳到登陆页
      }else{
        window.sessionStorage.removeItem("tempFlag");
      }
    }
    window.onunload = function (){
      window.sessionStorage["tempFlag"] = true;
    }
    window.onbeforeunload = function (){
      window.sessionStorage["tempFlag"] = true;
    }

    // window.addEventListener('beforeunload', e => {
    //   console.log(e)
    //   VueCookies.remove("store-current-user")
    //   this.websocketclose();
    // });
  },
  methods: {
    // getApiData:function(){
    //   Vue.axios.get('/api/message_count').then((response) => {
    //     alert(JSON.stringify(response.data))
    //     console.log(response.data)
    //     }).catch(err=>{
    //       console.log(err)
    //     })
    //     },
    chang(){
      this.value1=""
    },
    getMessageCount () {
        this.loading = true
        notReadMessage().then((res) => {
         this.value2=res.data
         if(this.value2>0){
           this.value1='New'
         }else{
            this.value1=""
         }
         this.loading = false
      }).catch((err) => {
        this.$message.error(err.message)
        this.loading = false
      })
    },
    initWebSocket() {
      //初始化weosocket
      let user = GetCurrentUser();
      const wsuri = "ws://39.98.173.131:8080/wlhse/ws?token="+user.token; //ws地址
      this.websocket = new WebSocket(wsuri);
      this.websocket.onopen = this.websocketonopen;
      this.websocket.onerror = this.websocketonerror;
      this.websocket.onmessage = this.websocketonmessage;
      this.websocket.onclose = this.websocketclose;
    },
     websocketonopen() {//连接建立之后执行send方法发送数据
      // alert("WebSocket连接成功");
      console.log("WebSocket连接成功");
    },
    websocketonerror() {
      //错误
      console.log("WebSocket连接发生错误");
      // console.log("WebSocket连接发生错误"+e.code);
    },
    websocketonmessage(e) {
      //数据接收
      // alert(JSON.parse(JSON.stringify(e.data)))
      const redata = JSON.parse(e.data);
      this.messageText=redata.data.messageText
      this.messageDate=redata.data.messageDate
      this.messageId=redata.data.messageId
      if(this.messageText=='{}')
      {
        this.addEventdialogVisible=false
      }else{
        this.addEventdialogVisible=true   
      }
      // alert(JSON.stringify(h))
      // alert(JSON.stringify(this.messageText))
      //注意：长连接我们是后台直接1秒推送一条数据，
      //但是点击某个列表时，会发送给后台一个标识，后台根据此标识返回相对应的数据，
      //这个时候数据就只能从一个出口出，所以让后台加了一个键，例如键为1时，是每隔1秒推送的数据，为2时是发送标识后再推送的数据，以作区分
      // console.log(redata.value);
    },
    websocketsend(agentData) {
      //数据发送
      this.websock.send(agentData);
    },
    websocketclose() {
      //关闭
      // console.log("connection closed (" + e.code + ")");
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    checkUser () {
      if (!this.currentUser) {
        this.$message.error('请登录')
        this.$router.push({name: 'Login'})
      }
    },
    handleDropCommand (cmd) {
      this[cmd]()
    },
    handleLogout () {
      CurrentUser.clear()
      this.$router.push({name: 'Login'})
    },
    //提交信息状态
    handleSubmit () {
      // alert(JSON.stringify(this.messageId))
      updateMessage(this.messageId).then(() => {
        // alert("成功！")
        this.$message.success('操作成功')
        // this.getMessageCount()
        this.addEventdialogVisible = false;
      }, (err) => {
        this.$message.error(err.message)
      })
    },
    GetModule () {
      let item = []
      let title = []
      let xitongguanli = []
      let shujupeizhi = []
      let wentiguanli = []
      let wentifenxi = []
      // let shigushijian = []
      let xuexianli= []
      let gerenzhongxin = []

      //addmenu
      let changqingtaskmanagement = []
      let changqingproblemmanagement = []
      let changqingpersonalcenter = []

      //audit
      let hesaudit = []

      GetNaviByUserRole().then((res) => {
        let data = res.data
        // console.log(111,JSON.stringify(data))
        for(let i =0;i<data.length;i++){
          title.push(data[i].title)
          if(data[i].title == '系统管理'){
            for(let j = 0;j<data[i].children.length;j++){
              xitongguanli.push(data[i].children[j].title)
            }
          }
          if(data[i].title == '数据配置'){
            for(let j = 0;j<data[i].children.length;j++){
              shujupeizhi.push(data[i].children[j].title)
            }
          }
          if(data[i].title == '问题管理'){
            for(let j = 0;j<data[i].children.length;j++){
              wentiguanli.push(data[i].children[j].title)
            }
          }
          if(data[i].title == '统计分析'){
            for(let j = 0;j<data[i].children.length;j++){
              wentifenxi.push(data[i].children[j].title)
            }
          }
          // if(data[i].title == '事故事件'){
          //   for(let j = 0;j<data[i].children.length;j++){
          //     shigushijian.push(data[i].children[j].title)
          //   }
          // }
           if(data[i].title == '学习共享'){
            for(let j = 0;j<data[i].children.length;j++){
              xuexianli.push(data[i].children[j].title)
            }
          }    
          if(data[i].title == '个人中心'){
            for(let j = 0;j<data[i].children.length;j++){
              gerenzhongxin.push(data[i].children[j].title)
            }
          }
          
          //addmenu
          if(data[i].title == '监督检查'){
          for(let j = 0;j<data[i].children.length;j++){
            changqingtaskmanagement.push(data[i].children[j].title)
            }
          }
          
          if(data[i].title == '违章管理'){
            for(let j = 0;j<data[i].children.length;j++){
              changqingproblemmanagement.push(data[i].children[j].title)
              }
            }
            
          if(data[i].title == '长庆个人中心'){
            for(let j = 0;j<data[i].children.length;j++){
              changqingpersonalcenter.push(data[i].children[j].title)
              }
            }

          if(data[i].title == 'HSE审核'){
            for(let j = 0;j<data[i].children.length;j++){
              hesaudit.push(data[i].children[j].title)
            }
          }

        }


          if(title.indexOf('安全概览') > -1){
            for(let i =0;i<data.length;i++){
              if(data[i].title == '安全概览'){
                data[i].icon = IconDashBoard
                item.push(data[i])
              }
            }
          }
          if(title.indexOf('系统管理') > -1){
            let itemChildren = []
            for(let i =0;i<data.length;i++){
              if(data[i].title == '系统管理'){
                if(xitongguanli.indexOf('角色管理') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '角色管理')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(xitongguanli.indexOf('组织机构') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '组织机构')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(xitongguanli.indexOf('员工管理') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '员工管理')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(xitongguanli.indexOf('角色授权') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '角色授权')
                    itemChildren.push(data[i].children[j])
                  }
                }
                // if(xitongguanli.indexOf('数据字典') > -1){
                //   for(let j = 0;j<data[i].children.length;j++){
                //     if(data[i].children[j].title == '数据字典')
                //     itemChildren.push(data[i].children[j])
                //   }
                // }
              
                data[i].icon = IconSystem
                data[i].children = itemChildren
                item.push(data[i])
              }
            }
          }
          if(title.indexOf('数据配置') > -1){
            let itemChildren = []
             for(let i =0;i<data.length;i++){
              if(data[i].title == '数据配置'){
                if(shujupeizhi.indexOf('发布版本') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '发布版本')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(shujupeizhi.indexOf('数据字典') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '数据字典')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(shujupeizhi.indexOf('检查项配置') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '检查项配置')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(shujupeizhi.indexOf('检查表配置') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '检查表配置')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(shujupeizhi.indexOf('领导检查项配置') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '领导检查项配置')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(shujupeizhi.indexOf('任务工序配置') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '任务工序配置')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(shujupeizhi.indexOf('任务目标配置') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '任务目标配置')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(shujupeizhi.indexOf('检查类型配置') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '检查类型配置')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(shujupeizhi.indexOf('问题类别配置') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '问题类别配置')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(shujupeizhi.indexOf('问题描述配置') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '问题描述配置')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(shujupeizhi.indexOf('人员检查地点配置') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '人员检查地点配置')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(shujupeizhi.indexOf('区域单位配置') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '区域单位配置')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(shujupeizhi.indexOf('问题原因配置') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '问题原因配置')
                    itemChildren.push(data[i].children[j])
                  }
                }

                data[i].icon = IconConfig
                data[i].children = itemChildren
                item.push(data[i])
              }
            }
          }
          if(title.indexOf('问题管理') > -1){
            let itemChildren = []
             for(let i =0;i<data.length;i++){
              if(data[i].title == '问题管理'){
                if(wentiguanli.indexOf('任务管理') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '任务管理')
                    itemChildren.push(data[i].children[j])
                  }
                }
                // if(wentiguanli.indexOf('编制计划') > -1){
                //   for(let j = 0;j<data[i].children.length;j++){
                //     if(data[i].children[j].title == '编制计划')
                //     itemChildren.push(data[i].children[j])
                //   }
                // }
                if(wentiguanli.indexOf('计划内问题录入') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '计划内问题录入')
                    itemChildren.push(data[i].children[j])
                  }
                }
                 if(wentiguanli.indexOf('计划外问题录入') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '计划外问题录入')
                    itemChildren.push(data[i].children[j])
                  }
                }
                 if(wentiguanli.indexOf('联系点录入') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '联系点录入')
                    itemChildren.push(data[i].children[j])
                  }
                }
                  if(wentiguanli.indexOf('批量录入') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '批量录入')
                    itemChildren.push(data[i].children[j])
                  }
                }

                if(wentiguanli.indexOf('问题审核') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '问题审核')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(wentiguanli.indexOf('问题清单') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '问题清单')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(wentiguanli.indexOf('问题整改') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '问题整改')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(wentiguanli.indexOf('问题验证') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '问题验证')
                    itemChildren.push(data[i].children[j])
                  }
                }
     

                data[i].icon = IconList
                data[i].children = itemChildren
                item.push(data[i])
              }
            }
          }
          
          if(title.indexOf('巡检管理') > -1){
             for(let i =0;i<data.length;i++){
              if(data[i].title == '巡检管理'){
                data[i].icon = IconPatrol
                item.push(data[i])
              }
            }
          }
          // if(title.indexOf('事故事件') > -1){
          //   let itemChildren = []
          //    for(let i =0;i<data.length;i++){
          //     if(data[i].title == '事故事件'){
          //       if(shigushijian.indexOf('事故') > -1){
          //         for(let j = 0;j<data[i].children.length;j++){
          //           if(data[i].children[j].title == '事故')
          //           itemChildren.push(data[i].children[j])
          //         }
          //       }
          //       if(shigushijian.indexOf('事件') > -1){
          //         for(let j = 0;j<data[i].children.length;j++){
          //           if(data[i].children[j].title == '事件')
          //           itemChildren.push(data[i].children[j])
          //         }
          //       }

          //       data[i].icon = IconEventAndAccident
          //       data[i].children = itemChildren
          //       item.push(data[i])
          //     }
          //   }
          // }
          if(title.indexOf('统计分析') > -1){
            let itemChildren = []
             for(let i =0;i<data.length;i++){
              if(data[i].title == '统计分析'){
                if(wentifenxi.indexOf('问题趋势') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '问题趋势')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(wentifenxi.indexOf('任务工序') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '任务工序')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(wentifenxi.indexOf('按单位分析') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '按单位分析')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(wentifenxi.indexOf('按责任人') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '按责任人')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(wentifenxi.indexOf('指标体系') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '指标体系')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(wentifenxi.indexOf('监督业绩') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '监督业绩')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(wentifenxi.indexOf('按问题级别') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '按问题级别')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(wentifenxi.indexOf('按事故分析') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '按事故分析')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(wentifenxi.indexOf('按事件分析') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '按事件分析')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(wentifenxi.indexOf('按问题严重程度分析') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '按问题严重程度分析')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(wentifenxi.indexOf('按岗位分析') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '按岗位分析')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(wentifenxi.indexOf('按岗位工龄分析') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '按岗位工龄分析')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(wentifenxi.indexOf('按问题原因分析') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '按问题原因分析')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(wentifenxi.indexOf('按问题对应要素分析') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '按问题对应要素分析')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(wentifenxi.indexOf('按问题管理模块分析') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '按问题管理模块分析')
                    itemChildren.push(data[i].children[j])
                  }
                }

                data[i].icon = IconAnalysis
                data[i].children = itemChildren
                item.push(data[i])
              }
            }
          }
          if(title.indexOf('学习共享') > -1){
            let itemChildren = []
             for(let i =0;i<data.length;i++){
              if(data[i].title == '学习共享'){
                if(xuexianli.indexOf('规章制度') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '规章制度')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(xuexianli.indexOf('文件通知') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '文件通知')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(xuexianli.indexOf('管理亮点') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '管理亮点')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(xuexianli.indexOf('上传规章制度') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '上传规章制度')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(xuexianli.indexOf('上传文件通知') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '上传文件通知')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(xuexianli.indexOf('上传管理亮点') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '上传管理亮点')
                    itemChildren.push(data[i].children[j])
                  }
                }

                if(xuexianli.indexOf('典型隐患') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '典型隐患')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(xuexianli.indexOf('上传事故') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '上传事故')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(xuexianli.indexOf('上传事件') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '上传事件')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(xuexianli.indexOf('事故') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '事故')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(xuexianli.indexOf('事件') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '事件')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(xuexianli.indexOf('案例') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '案例')
                    itemChildren.push(data[i].children[j])
                  }
                }

                data[i].icon = IconStudyCase
                data[i].children = itemChildren
                item.push(data[i])
              }
            }
          }
          if(title.indexOf('个人中心') > -1){
            let itemChildren = []
             for(let i =0;i<data.length;i++){
              if(data[i].title == '个人中心'){
                if(gerenzhongxin.indexOf('修改个人资料') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '修改个人资料')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(gerenzhongxin.indexOf('我下达的任务') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '我下达的任务')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(gerenzhongxin.indexOf('我接受的任务') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '我接受的任务')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(gerenzhongxin.indexOf('我编制的计划') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '我编制的计划')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(gerenzhongxin.indexOf('我录入的问题') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '我录入的问题')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(gerenzhongxin.indexOf('我需整改的问题') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '我需整改的问题')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(gerenzhongxin.indexOf('我需验证的问题') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '我需验证的问题')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(gerenzhongxin.indexOf('我单位的问题') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '我单位的问题')
                    itemChildren.push(data[i].children[j])
                  }
                }

                data[i].icon = IconPersonalCenter
                data[i].children = itemChildren
                item.push(data[i])
              }
            }
          }

          //addmenu
          if(title.indexOf('监督检查') > -1){
            let itemChildren = []
            for(let i =0;i<data.length;i++){
              if(data[i].title == '监督检查'){
                if(changqingtaskmanagement.indexOf('下达任务') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '下达任务')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(changqingtaskmanagement.indexOf('管理任务') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '管理任务')
                    itemChildren.push(data[i].children[j])
                  }
                }
              
                data[i].icon = IconSupervision
                data[i].children = itemChildren
                item.push(data[i])
              }
            }
          }
          
          if(title.indexOf('违章管理') > -1){
            let itemChildren = []
            for(let i =0;i<data.length;i++){
              if(data[i].title == '违章管理'){
                if(changqingproblemmanagement.indexOf('问题录入') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '问题录入')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(changqingproblemmanagement.indexOf('问题整改') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '问题整改')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(changqingproblemmanagement.indexOf('问题审核') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '问题审核')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(changqingproblemmanagement.indexOf('问题清单') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '问题清单')
                    itemChildren.push(data[i].children[j])
                  }
                }
                if(changqingproblemmanagement.indexOf('批量导入') > -1){
                  for(let j = 0;j<data[i].children.length;j++){
                    if(data[i].children[j].title == '批量导入')
                    itemChildren.push(data[i].children[j])
                  }
                }
              
                data[i].icon = IconRegulations
                data[i].children = itemChildren
                item.push(data[i])
              }
            }
          }
          
           if(title.indexOf('长庆个人中心') > -1){
             let itemChildren = []
             for(let i =0;i<data.length;i++){
               if(data[i].title == '长庆个人中心'){
                 if(changqingpersonalcenter.indexOf('工作提醒') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == '工作提醒')
                     itemChildren.push(data[i].children[j])
                   }
                 }
                 if(changqingpersonalcenter.indexOf('我下达的任务') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == '我下达的任务')
                     itemChildren.push(data[i].children[j])
                   }
                 }
                 if(changqingpersonalcenter.indexOf('我接收的任务') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == '我接收的任务')
                     itemChildren.push(data[i].children[j])
                   }
                 }
                 if(changqingpersonalcenter.indexOf('我待提交的问题') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == '我待提交的问题')
                     itemChildren.push(data[i].children[j])
                   }
                 }
                 if(changqingpersonalcenter.indexOf('我待审核的问题') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == '我待审核的问题')
                     itemChildren.push(data[i].children[j])
                   }
                 }
                 if(changqingpersonalcenter.indexOf('我待整改的问题') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == '我待整改的问题')
                     itemChildren.push(data[i].children[j])
                   }
                 }
                 if(changqingpersonalcenter.indexOf('我整改的问题') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == '我整改的问题')
                     itemChildren.push(data[i].children[j])
                   }
                 }
                 if(changqingpersonalcenter.indexOf('我待验证的问题') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == '我待验证的问题')
                     itemChildren.push(data[i].children[j])
                   }
                 }
                 if(changqingpersonalcenter.indexOf('我验证的问题') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == '我验证的问题')
                     itemChildren.push(data[i].children[j])
                   }
                 }
                 if(changqingpersonalcenter.indexOf('我录入的问题') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == '我录入的问题')
                     itemChildren.push(data[i].children[j])
                   }
                 }

                 data[i].icon = IconCQPerson
                 data[i].children = itemChildren
                 item.push(data[i])
               }
             }
           }

           if(title.indexOf('HSE审核') > -1){
             let itemChildren = []
             for(let i =0;i<data.length;i++){
               if(data[i].title == 'HSE审核'){
                 if(hesaudit.indexOf('HSE任务管理') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == 'HSE任务管理')
                     itemChildren.push(data[i].children[j])
                   }
                 }

                 if(hesaudit.indexOf('HSE审核组设置') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == 'HSE审核组设置')
                     itemChildren.push(data[i].children[j])
                   }
                 }
                 
                 if(hesaudit.indexOf('HSE审核主题分配') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == 'HSE审核主题分配')
                     itemChildren.push(data[i].children[j])
                   }
                 }

                 if(hesaudit.indexOf('HSE问题录入') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == 'HSE问题录入')
                     itemChildren.push(data[i].children[j])
                   }
                 }

                 if(hesaudit.indexOf('HSE组长审核') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == 'HSE组长审核')
                     itemChildren.push(data[i].children[j])
                   }
                 }

                 if(hesaudit.indexOf('HSE问题清单') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == 'HSE问题清单')
                     itemChildren.push(data[i].children[j])
                   }
                 }

                 if(hesaudit.indexOf('HSE问题整改') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == 'HSE问题整改')
                     itemChildren.push(data[i].children[j])
                   }
                 }

                 if(hesaudit.indexOf('HSE问题验证') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == 'HSE问题验证')
                     itemChildren.push(data[i].children[j])
                   }
                 }

                  if(hesaudit.indexOf('HSE审核人员管理') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == 'HSE审核人员管理')
                     itemChildren.push(data[i].children[j])
                   }
                 }

                 if(hesaudit.indexOf('HSE录入问题管理') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == 'HSE录入问题管理')
                     itemChildren.push(data[i].children[j])
                   }
                 }

                 if(hesaudit.indexOf('HSE问题统计') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == 'HSE问题统计')
                     itemChildren.push(data[i].children[j])
                   }
                 }

                 if(hesaudit.indexOf('HSE管理员审核') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == 'HSE管理员审核')
                     itemChildren.push(data[i].children[j])
                   }
                 }

                 if(hesaudit.indexOf('HSE组内问题清单') > -1){
                   for(let j = 0;j<data[i].children.length;j++){
                     if(data[i].children[j].title == 'HSE组内问题清单')
                     itemChildren.push(data[i].children[j])
                   }
                 }

                 data[i].icon = IconAudit
                 data[i].children = itemChildren
                 item.push(data[i])
               }
             }
           }

           if(title.indexOf('体系审核') > -1){
            for(let i =0;i<data.length;i++){
              if(data[i].title == '体系审核'){
                data[i].icon = IconDashBoard
                item.push(data[i])
              }
            }
          }
          if(title.indexOf('属地检查') > -1){
            for(let i =0;i<data.length;i++){
              if(data[i].title == '属地检查'){
                data[i].icon = IconDashBoard
                item.push(data[i])
              }
            }
          }
          if(title.indexOf('日常检查') > -1){
            for(let i =0;i<data.length;i++){
              if(data[i].title == '日常检查'){
                data[i].icon = IconDashBoard
                item.push(data[i])
              }
            }
          }

        this.navs = item
        //console.log('this.navs', this.navs)
      }).catch((err) => {
        this.$message.error(err.message)
      })
    },
    toggleCollapse() {
      this.isCollapse = ! this.isCollapse
    }
  },
  computed: {
    activeNav () {
      let navs = this.navs
      let routeName = this.$route.name
      for (let nav of navs) {
        if (nav.children && nav.children.length > 0) {
          for (let child of nav.children) {
            if (child.routes.includes(routeName)) {
              return child.routeName
            }
          }
        } else {
          if (nav.routes.includes(routeName)) {
            return nav.routeName
          }
        }
      }
      return 'Home'
    },
    // currentUser () {
    //   return CurrentUser.get()
    // }
     currentUser(){
      return GetCurrentUser()
    },
  }

}
</script>

<style lang='scss' scoped>
.layout-base {
  background: #F4F4F4;
  height: 100vh;

  .layout-aside {
    overflow: hidden;
    background: #545C64;
    display: flex;
    flex-direction: column;
    align-items: stretch;

    .menu-header {
      background: #fff;
      font-size: 17px;
      padding: 5px;
      line-height: 30px;
      font-weight: bold;
      display: flex; 
      justify-content: flex-start;
      align-items: center; 
    }

    .layout-menu {
      flex: 1 1;
      border: none;
      overflow-y: auto;
      overflow-x: hidden;

      .nav-text-inline {
        display: flex;
        align-items: center;
        img {
          margin-right: 8px;
          opacity: 0.7;
        }
      }
    }
  }
  .main-header {
    background: #fff;
    padding: 15px;
    line-height: 30px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
 
}
 img.logo { 
  height: 50px;
  margin-right: 10px;
}

.toggle-button {
    font-size: 16px;
    line-height: 24px;
    margin: 0 40% 0 25%;
    color: #F4F4F4;
    letter-spacing: 0.1em;
    cursor: pointer;
}
</style>
